package cn.net.cfss.fgbp.provider.console.biz;

import cn.net.cfss.fgbp.api.console.constant.DeleteFlagEnum;
import cn.net.cfss.fgbp.api.console.dto.SysRoleProjectDto;
import cn.net.cfss.fgbp.api.console.vo.ProjectVo;
import cn.net.cfss.fgbp.base.common.biz.BaseBiz;
import cn.net.cfss.fgbp.provider.console.dao.SysRoleProjectDtoMapper;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.*;

/**
 * @author tj
 * @title: SysRoleProjectDtoBiz
 * @description: TODO
 */
@Service
public class SysRoleProjectDtoBiz extends BaseBiz<SysRoleProjectDtoMapper, SysRoleProjectDto> {

    @Transactional
    public void deleteBatch(List<Long> roleIds) {
        mapper.deleteBatch(roleIds);
    }

    @Transactional
    public void add(Long roleId, List<ProjectVo> project) {
        if (project != null && project.size() > 0) {
            for (ProjectVo proj : project) {
                SysRoleProjectDto dto = new SysRoleProjectDto();
                dto.setProjPkId(proj.getId());
                dto.setRoleId(roleId);
                dto.setId(getUID());
                dto.setDeleteFlag(DeleteFlagEnum.NOT_DEL);
                dto.setCreateTime(new Date());
                dto.setUpdateTime(new Date());
                mapper.insert(dto);
            }
        }

    }

    @Transactional
    public void updateByRoleId(Long roleId, List<ProjectVo> projects) {
        SysRoleProjectDto dto = new SysRoleProjectDto();
        dto.setRoleId(roleId);
        mapper.delete(dto);
        add(roleId, projects);
    }

    public List<SysRoleProjectDto> queryByRoleIds(List<Long> roleIds) {
        return mapper.queryByRoleIds(roleIds);
    }

    public List<SysRoleProjectDto> queryByRoleIds(Long roleIds) {
        List<Long> list = new ArrayList<>();
        list.add(roleIds);
        return mapper.queryByRoleIds(list);
    }

    public List<String> getProjects(List<Long> roleIds) {
        return mapper.getProjects(roleIds);
    }

}
